﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class UC_testsite : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void createUserWizardStep2_Load(object sender, EventArgs e)
    {
        DropDownList agesDDL = createUserWizardStep2.FindControl("AgeYearDDL") as DropDownList;

        for (int i = 1900; i < 2000; i++)
        {
            ListItem ages = new ListItem();
            ages.Text = i.ToString();
            agesDDL.Items.Add(ages);

        }

        DropDownList monthDDL = createUserWizardStep2.FindControl("AgeMonthDDL") as DropDownList;
        string[] months = { "Januar", "Februar", "Marts", "April", "Maj", "Juni", "Juli", "August", "September", "Oktober", "November", "December" };

        foreach (var item in months)
        {
            ListItem mon = new ListItem();
            mon.Text = item;
            monthDDL.Items.Add(mon);
        }

        DropDownList daysDDL = createUserWizardStep2.FindControl("AgeDayDDL") as DropDownList;

        for (int i = 1; i < 32; i++)
        {
            ListItem days = new ListItem();
            days.Text = i.ToString();
            daysDDL.Items.Add(days);
        }
    }

    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        TextBox usernameTxt = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
        MembershipUser LoggedInUser = Membership.GetUser(usernameTxt.Text);

        DateiaftenDataContext db = new DateiaftenDataContext();
        var DbUser = db.aspnet_Users.SingleOrDefault(x => x.UserName.Equals(LoggedInUser.UserName));
        DbUser.FirstName = FirstName.Text;
        DbUser.LastName = LastName.Text;
        DateTime age = new DateTime(Convert.ToInt32(AgeYearDDL.SelectedItem.Text), returnMonthNumber(AgeMonthDDL.SelectedItem.Text), Convert.ToInt32(AgeDayDDL.SelectedItem.Text));
        DbUser.Age = age;


        var gender = db.Genders.SingleOrDefault(x => x.sex.Equals(Gender.SelectedValue));
        DbUser.Gender = gender;
        db.SubmitChanges();

    }

    protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {

    }

    protected int returnMonthNumber(string month)
    {
        switch (month)
        {
            case "Januar":
                return 1;
            case "Februar":
                return 2;
            case "Marts":
                return 3;
            case "April":
                return 4;
            case "Maj":
                return 5;
            case "Juni":
                return 6;
            case "Juli":
                return 7;
            case "August":
                return 8;
            case "September":
                return 9;
            case "Oktober":
                return 10;
            case "November":
                return 11;
            case "December":
                return 12;
            default:
                return 0;
        }
    }


    protected void Continue_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }

    

}